package com.shamar.blog.exceptions;

import com.shamar.blog.enums.ExceptionEnum;
import com.shamar.blog.enums.TradeStatusEnum;

import java.text.MessageFormat;

/**
 * @ClassName SystemException
 * @Description 系统异常类
 * @Author husheng
 * @Date 2020-01-04 15:00
 */
public class SystemException extends RuntimeException{

    private TradeStatusEnum tradeStatus;

    private String code;

    private String msg;

    public SystemException() {
        super();
    }

    public SystemException(ExceptionEnum bizExceptionEnum) {
        this(bizExceptionEnum.name(), bizExceptionEnum.getMsg(),null);
    }

    public SystemException(ExceptionEnum bizExceptionEnum, TradeStatusEnum tradeStatus) {
        this(bizExceptionEnum.name(), bizExceptionEnum.getMsg(), tradeStatus);
    }

    public SystemException(ExceptionEnum bizExceptionEnum, String msg, TradeStatusEnum tradeStatus) {
        this(bizExceptionEnum.name(), msg, tradeStatus);
    }

    public SystemException(ExceptionEnum bizExceptionEnum, String msg) {
        this(bizExceptionEnum.name(), msg, null);
    }

    public SystemException(ExceptionEnum bizExceptionEnum, String... args) {
        this(bizExceptionEnum.name(), String.format(bizExceptionEnum.getMsg(), args),null);
    }

    public SystemException(String errorCode, String errorMsg, TradeStatusEnum tradeStatus) {
        super(MessageFormat.format("code:{0}, msg:{1}", errorCode, errorMsg));
        this.code = errorCode;
        this.msg = errorMsg;
        this.tradeStatus = tradeStatus;
    }

    public static SystemException newValidateInstance(String... args) {
        return new SystemException(ExceptionEnum.V00000, args);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public TradeStatusEnum getTradeStatus() {
        return tradeStatus;
    }

    public void setTradeStatus(TradeStatusEnum tradeStatus) {
        this.tradeStatus = tradeStatus;
    }

    public static void main(String[] args) {
        SystemException systemException = SystemException.newValidateInstance("pay");
        System.out.println(systemException.msg);
    }
}
